const ioredis = require('ioredis')

const BOTTLE_KEY = 'bottle'

// 创建 redis 对象
const redis = new ioredis({
  port: 6379,
  host: '127.0.0.1',
  showFriendlyErrorStack: true, // 生产建议关闭，优化错误堆栈会影响性能
})

const driftBottle = async (data) => {
  const lLen = await redis.lpush(BOTTLE_KEY, JSON.stringify(data))
  return lLen
}

const getBottle = async () => {
  const ret = await redis.lpop(BOTTLE_KEY)
  console.log(ret)
  return JSON.parse(ret)
}

exports.driftBottle = driftBottle
exports.getBottle = getBottle

